package uqbar.comm;

import gnu.io.CommPortIdentifier;

import java.util.Enumeration;

public class CommonsPortNames {

	private static String PORT_NAMES[] = { "/dev/tty.usbserial-A9007UX1", "/dev/ttyUSB0", "COM3", "/dev/ttyACM0" };

	public static CommPortIdentifier find() {
		@SuppressWarnings("unchecked")
		Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();

		// iterate through, looking for the port
		while (portEnum.hasMoreElements()) {
			CommPortIdentifier currPortId = portEnum.nextElement();
			for (String portName : PORT_NAMES) {
				if (currPortId.getName().equals(portName)) {
					return currPortId;
				}
			}
		}
		throw new RuntimeException("No existe ninguno de los puertos conocidos en la máquina");
	}
}
